package is.server.controller.session.remote;

import is.common.datatype.Request;
import is.common.interfaces.Command;
import is.common.syntax.CommandQualifier;
import is.common.util.ObjectStreamer;
import is.server.controller.session.remote.command.*;

/**
 * Factory returns commands according to user input.
 *
 * @author aspr0
 *         Date: 07.04.12
 *         Time: 12:05
 */
public class CommandFactory
{
    public static Command newInstance(Request request, ObjectStreamer objectStreamer)
    {
        String commandQualifier = request.getCommandQualifier();

        if (CommandQualifier.ADD.equals(commandQualifier))
        {
            return new AddCommand(request, objectStreamer);
        }
        else if (CommandQualifier.DROP.equals(commandQualifier))
        {
            return new DropCommand(request, objectStreamer);
        }
        else if (CommandQualifier.EDIT.equals(commandQualifier))
        {
            return new EditCommand(request, objectStreamer);
        }
        else if (CommandQualifier.LIST_ROWS.equals(commandQualifier))
        {
            return new ListRowsCommand(request, objectStreamer);
        }
        else if (CommandQualifier.LIST_HEADER.equals(commandQualifier))
        {
            return new ListHeaderCommand(request, objectStreamer);
        }
        else if (CommandQualifier.FIND.equals(commandQualifier))
        {
            return new FindCommand(request, objectStreamer);
        }
        else if (CommandQualifier.CONCAT.equals(commandQualifier))
        {
            return new ConcatCommand(objectStreamer);
        }
        else
        {
            return new UnknownCommand();
        }
    }

}
